<?php
/**
 * Created by PhpStorm.
 * User: gaochaolyf
 * Date: 16/5/30
 * Time: 下午3:09
 */

namespace api\Model;

use Think\Model;

class IntegerCasesModel extends Model
{
    function __construct() {
        $this->model = M('IntegerCases');
    }

    public function getCasesList($field = array('*'), $condition = array(), $page = 1, $pergage = 20, $order = 'sort asc') {
        $data = $this->model->where($condition)->field($field)->page($page, $pergage)->order($order)->select();
        $data = $data ? $data : array();

        return $data;
    }

    public function getOneCases($field = array('*'), $condition = array()) {
        $data = $this->model->where($condition)->field($field)->find();
        $data = $data ? $data : array();

        return $data;
    }

    public function addOneCases($param = array()) {
        $insert_id = $this->model->data($param)->add();

        return $insert_id;
    }

    public function updateOneCases($param = array(), $condition = array()) {
        $affected = $this->model->where($condition)->setField($param);

        return $affected;
    }

    public function getCasesCount($condition) {
        $count = $this->model->where($condition)->count();

        return $count;
    }

    public function getCasesById($cases_id = 0, $field = array('*')) {
        $data = $this->model->where(array('integer_cases_id' => $cases_id))->field($field)->find();
        $data = $data ? $data : array();

        return $data;
    }
}